<template>
    <view>
        <view class="logo">
            <view class="logo-img">
                <img :src="base_url + '/logo.png'" alt="" style="width:100%;height:100%">
            </view>
            <view class="name">农乎小程序</view>
        </view>
        <view class="wx-login">
            <view class="wx-login-icon iconfont icon-weixin1" style="color:#fff;font-size:40rpx">
                
            </view>
            <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">微 信 登 录</button>
        </view>
        <!-- <view class="phone-login">
            <view class="phone-login-icon iconfont icon-shouji01" style="color:#24C79C;font-size:40rpx">
                
            </view>
            <button @tap="goLoginByPhone">手 机 登 录</button>
        </view> -->
    </view>
</template>

<script>
import { config } from '../../common/utils/congfig'
import { UserModel } from '../../model/user.js'
const userModel = new UserModel()
export default {
    data() {
        return {
            base_url: config.img_base_url,
            backPage: ''
        }
    },
    methods: {
        getPhoneNumber(e) {
            console.log(e)
            let data = {
                encrypted_data: encodeURIComponent(e.detail.encryptedData),
                iv: encodeURIComponent(e.detail.iv)
            }
            userModel.getUserPhoneNumber(data).then((res) => {
                if(res.code == 200) {
                    uni.showToast({
                        title: '登录成功'
                    })
                    uni.setStorageSync('userPhone', res.data.phone)
                    let userInfo = uni.getStorageSync('wxuserInfo')
                    if(!userInfo) {
                        uni.redirectTo({
                            url: '/pagesB/login/login-userInfo'
                        })
                    }else {
                        uni.navigateBack({
                            delta: 1
                        })
                    }
                }
            })
        }
    },
    onLoad(option) {
        console.log(option)
        this.backPage = option.backpage
    }
}
</script>

<style>
    page {
        background: #FFFFFF;
    }
    .logo {
        width: 624rpx;
        height: 440rpx;
        margin: 0 auto;
        overflow: hidden;
    }
    .logo-img {
        width: 142rpx;
        height: 142rpx;
        margin: 112rpx auto 21rpx;
    }
    .name {
        color: #F9531F;
        font-size: 28rpx;
        font-weight: bold;
        text-align: center;
    }
    .wx-login,
    .phone-login {
        position: relative;
        width: 624rpx;
        height: 84rpx;
        margin: 0 auto;
    }
    .phone-login {
        margin-top: 61rpx;
    }
    .wx-login-icon,
    .phone-login-icon {
        position: absolute;
        left: 189rpx;
        top: 20rpx;
        width: 37rpx;
        height: 31rpx;
        z-index: 9999;
    }
    .phone-login-icon {
        width: 23rpx;
        height: 37rpx;
    }
    .wx-login button,
    .phone-login button {
        width: 100%;
        height: 100%;
        background:rgba(36,199,156,1);
        box-shadow: 0rpx 0rpx 29rpx 0rpx rgba(0,58,96,0.05);
        border-radius: 42rpx;
        color: #FFFFFF;
        font-size: 30rpx;
        font-weight: 500;
        text-align: center;
        line-height: 84rpx;
    }
    .wx-login button::after,
    .phone-login button::after {
        border: none;
    }
    .phone-login button {
        background:rgba(255,255,255,1);
        color: #333333;
    }
</style>